﻿--[[
   @brief    install path mgr view
   @author   maxyao
   @version  1.0
   @date     2019-09-23
--]]

install_path_mgr_view = 
{
    pDialog_ = nil;
    dwRootId_ = 0;
    pWeb_ptr_ = nil;
    pClose_btn_dlg = nil;
    -- shadow_ptr_ = nil;
    shadow_id_ = 0;
    
    dialog_id = 0;
    page_url = LoadStr("INSTALL_PATH_MGR_URL");
}

function install_path_mgr_view:init()
    base_utility.log("[install_path_mgr_view] init ");
end

function install_path_mgr_view:show(bShow)
    if bShow == true then
         local param = {
            url = install_path_mgr_view.page_url;
            use_ptlogin = false;
            width = 682;
            height = 536;
            caption = LoadStr("INSTALL_PATH_MGR");
            show_loading_page = false;
            region_set_zero = true;
            reload = true;
            title_in_web = true;
        };
        install_path_mgr_view.dialog_id = comm_center.call_service("i_service_show_simple_web_window", param);
    else
        local param = {id = install_path_mgr_view.dialog_id};
        comm_center.call_service("i_service_close_simple_web_window",param);
    end
end

function install_path_mgr_view:create()
    if self.pDialog_ ~= nil then
        return true;
    end
    self.dwRootId_ = layout_mgr.restore_layout("wegame_sys_menu\\InstallPathMgr.tpf");
    if self.dwRootId_ ~= 0 then
        self.pDialog_ =ui_utility.get_ctrl_ptr_by_id(self.dwRootId_);
        self.pWeb_ptr_ = ui_utility.get_ctrl_ptr_by_path(self.dwRootId_, "QBWebBrowser_Path_MGR");
        --[[
        self.pClose_btn_dlg = ui_utility.get_ctrl_ptr_by_path(self.dwRootId_, "CloseBtnCtn");
        if self.pDialog_ ~= nil then
            self.pClose_btn_dlg:MoveFollow(self.pDialog_:GetControlID(), 651, 9);
            self.pDialog_:MoveToCenter();
        end
        --]]
        if self.pWeb_ptr_ ~= nil then 
            self:flush_web();
            if self.pWeb_ptr_:IsVisible() == FALSE then
                local web_id = self.pWeb_ptr_:GetControlID();
                ui_utility.setproperty_by_id(
                    web_id, "OnNavigateFailed", "install_path_mgr_view:on_navigate_fail");
                ui_utility.setproperty_by_id(
                    web_id, "OnNavigateComplete", "install_path_mgr_view:on_navigate_ok");
            end
        end
        return true;
    else
        base_utility.log("[install_path_mgr_view] install_path_mgr_view error!!!");
        return false;
    end
end

function install_path_mgr_view:hide(uilib, ctrl_id)
    base_utility.log("[install_path_mgr_view] hide install_path_mgr_view tpf");
    if self.pDialog_ ~= nil then
        self.pDialog_:Show(FALSE);
    end
end

function install_path_mgr_view:flush_web()
    if self.pWeb_ptr_ ~= nil then
        local ui_str, str_holder = U8toCUIStr(self.page_url);
        self.pWeb_ptr_:Navigate(ui_str);
    end
end

function install_path_mgr_view:on_navigate_ok()
    base_utility.log("[install_path_mgr_view]Web navigate success");
    self:display_wnd();
end

function install_path_mgr_view:display_wnd()
    --shadow_helper.create_shadow(self.dwRootId_);
    self.pDialog_:Show(TRUE);
    self.pDialog_:BringToTop();
end

function install_path_mgr_view:on_navigate_fail()
    base_utility.log("[install_path_mgr_view]Web navigate fail");

end

function install_path_mgr_view:close()
    base_utility.log("[install_path_mgr_view] remove install_path_mgr_view tpf");
    if self.pDialog_ ~= nil then
        --shadow_helper.destroy_shadow(self.dwRootId_);
        self.pDialog_:Show(FALSE);
    end
    layout_mgr.delay_remove_ctrl(self.dwRootId_);
    self.dwRootId_ = 0;
    self.pDialog_ = nil;   
    if self.shadow_ptr_ ~= nil then
        self.shadow_ptr_:Show(FALSE);
    end
    layout_mgr.delay_remove_ctrl(self.shadow_id_);
    self.shadow_id_ = 0;
    self.shadow_ptr_ = nil; 
end

function install_path_mgr_view:min()
    if self.pDialog_ ~= nil then
        self.pDialog_:Minimize();
    end
end

function install_path_mgr_view:has_creat()
    return self.dwRootId_ ~= 0;
end


function install_path_mgr_view:resize(width, height)
    base_utility.log("[install_path_mgr_view] resize");
  
    if width > 0 and height > 0 then
        if nil ~= self.pDialog_ then
            local rtTemp = self.pDialog_:GetRectEx(FALSE,TRUE);

            rtTemp.right  = rtTemp.left + width + 2;
            rtTemp.bottom = rtTemp.top  + height + 2;

            self.pDialog_:MoveEx(rtTemp,TRUE);
        end;
    end
end

function install_path_mgr_view:on_show(uilib, ctrl_id)
    if self.pWeb_ptr_ ~= nil and self.pDialog_:IsDisable() == FALSE then
        self.pWeb_ptr_:SetFocus();
    end
end

function install_path_mgr_view:on_hide()
--    if nil ~= self.shadow_ptr_ then
--        self.shadow_ptr_:Show(FALSE);
--    end
end

function install_path_mgr_view:set_focus_dialog()
    if self.pDialog_ ~= nil then
        self.pDialog_:SetFocus();
    end
end

install_path_mgr_view.init();

